package com.java.simple.study.juc.p3;

import com.java.simple.study.tool.Sleeper;
import lombok.extern.slf4j.Slf4j;

/**
 * @author zhoujl
 * @date 2022/5/9 21:47
 * @desc
 */
public class TestMultiLock {

    public static void main(String[] args) {
        BigRoom bigRoom = new BigRoom();
        new Thread(() -> {
            bigRoom.sleep();
        }, "小南").start();
        new Thread(() -> {
            bigRoom.study();
        }, "小女").start();
    }

}

@Slf4j(topic = "c.BigRoom")
class BigRoom {
    private final Object sleepRoom = new Object();
    private final Object studyRoom = new Object();

    public void sleep() {
        synchronized (sleepRoom) {
            log.debug("sleep 2 小时");
            Sleeper.sleep(2);
        }
    }

    public void study() {
        synchronized (studyRoom) {
            log.debug("sleep 1 小时");
            Sleeper.sleep(1);
        }
    }

}
